package com.design.observer.socialmedia;

import java.util.ArrayList;
import java.util.List;

// 具体观察者类
class User implements Follower {
    private String name;

    public User(String name) {
        this.name = name;
    }

    @Override
    public void update(String message) {
        System.out.println(name + " received update: " + message);
    }
}

// 具体主题类
class SocialMediaInfluencer implements Influencer {
    private List<Follower> followers = new ArrayList<>();
    private String name;

    public SocialMediaInfluencer(String name) {
        this.name = name;
    }

    @Override
    public void addFollower(Follower follower) {
        followers.add(follower);
    }

    @Override
    public void removeFollower(Follower follower) {
        followers.remove(follower);
    }

    @Override
    public void notifyFollowers(String message) {
        System.out.println(name + " posted: " + message);
        for (Follower follower : followers) {
            follower.update(name + " posted: " + message);
        }
    }
}
